package com.ITArmy.controller;

import com.ITArmy.beans.Shows.UserFocus;
import com.ITArmy.beans.User;
import com.ITArmy.common.ServerResponse;
import com.ITArmy.controller.base.BaseController;
import com.ITArmy.service.CollectionService;
import com.ITArmy.util.GetUserSession;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

@Api(value = "所有收藏接口", tags = "所有收藏接口CollectionController")
@RequestMapping("/collection")
@Controller
public class CollectionController extends BaseController {
    GetUserSession getUserSession = new GetUserSession();


    @RequestMapping("/collectionBlog")
    @ApiOperation(value = "用户收藏博客", notes = "需要传到后端博客的:blogId",
            httpMethod = "POST", response = ServerResponse.class)
    @ResponseBody
    public ServerResponse collectionBlog( long blogId) {
        return collectionService.collectionBlog(request, blogId);
    }

    @RequestMapping("/collectionSerialize")
    @ApiOperation(value = "用户收藏连载", notes = "需要传到后端连载的:serializeId",
            httpMethod = "POST", response = ServerResponse.class)
    @ResponseBody
    public ServerResponse collectionSerialize(HttpServletRequest req, long serializeId) {
        return collectionService.collectionSerialize(req, serializeId);
    }

    @RequestMapping("/showCollectionBlog")
    @ApiOperation(value = "遍历用户收藏的所有的博客，跳转到收藏博客的页面",
            httpMethod = "POST", response = String.class)
    //遍历用户收藏的所有的博客，跳转到收藏博客的页面=============
    public String showCollectionBlog(HttpServletRequest request, Model model) {
        List<UserFocus> focusUsers = (List<UserFocus>) focusService.findAllFocuses(request).getData();
        model.addAttribute("serialize", collectionService.getSerializeCollection(request).getData());
        model.addAttribute("UserFocus", focusUsers);
        return "collectBlog";
    }

    @RequestMapping("/showCollectionSeriallize")
    @ApiOperation(value = "遍历用户收藏的所有的博客，跳转到收藏连载的页面",
            httpMethod = "POST", response = String.class)
    public String showCollectionSeriallize(HttpServletRequest request, Model model) {
        User uer = getUserSession.getUser(request);
        getUserSession.addUserModel(request, model);
        model.addAttribute("blogs", collectionService.getBlogCollection(request));
        return "";
    }

    @RequestMapping("/deleteBlogCollection")
    @ApiOperation(value = "用户取消收藏的博客", notes = "需要传到后端博客的:serializeId",
            httpMethod = "DELETE", response = ServerResponse.class)
    @ResponseBody
    public ServerResponse deleteBlogCollection(HttpServletRequest request, long blogId) {
        return collectionService.deleteBlogCollection(request, blogId);
    }

    @RequestMapping("/deleteSerializeCollection")
    @ApiOperation(value = "用户删除收藏的博客", notes = "需要传到后端连载的:serializeId",
            httpMethod = "DELETE", response = ServerResponse.class)
    @ResponseBody
    public ServerResponse deleteSerializeCollection(HttpServletRequest request, long SerializeId) {
        return collectionService.deleteSerializeCollection(request, SerializeId);
    }

}
